// -*- C++ -*------------------------------------------------------------------
//  $Id: PdbLoader.h,v 1.10 2008-08-03 21:26:35 biocomp Exp $
//
//  Class:              PdbLoader
//
//  Base Class(es):     Loader
//
//  Derived Class(es):  -
//
//  Containing:         -
//
//  Author:             Silvio Tosatto
//
//  Project Name:       Victor
//
//  Date:               09/99
//
//  Reviewed By:        <Name>
//
//  Description:
//    Loads components (Atoms, Groups, etc.) in standard PDB format.
//    NB: Only loadSpacer() is currently implemented.
//
// ---------------------------------------------------------------------------

#ifndef _PDB_LOADER_H_
#define _PDB_LOADER_H_

// Includes:
#include <string.h>
#include <utility>
#include <Loader.h>
#include <AminoAcid.h>
#include <Spacer.h>
#include <LigandSet.h>

// Global constants, typedefs, etc. (to avoid):

namespace Biopool {

class PdbLoader : public Loader
{
public: 

  // CONSTRUCTORS/DESTRUCTOR:
  PdbLoader(istream& _input = cin, bool _permissive = false, 
	    bool _noHAtoms = false, bool _noSecondary = false, 
	    bool _noConnection = false, bool _noWater = true, 
	    bool _verb = true) 
    : input(_input), permissive(_permissive), valid(true), 
      noHAtoms(_noHAtoms), noSecondary(_noSecondary), 
      noConnection(_noConnection), noWater(_noWater), verbose(_verb), 
      chain(' '), model(999), altAtom('A'), helixCode(""), sheetCode(""), 
      helixData(), sheetData() { }

  // this class uses the implicit copy operator.
  virtual ~PdbLoader() { PRINT_NAME; }  

  // PREDICATES:
  bool isValid() { return valid; }
  unsigned int getMaxModels();
  unsigned int getMaxModelsFast();
  vector<char> getAllChains();

  // MODIFIERS:
  void setPermissive() { permissive = true; }
  void setNonPermissive() { permissive = false; }
  void setNoVerbose() { verbose = false; }
  void setVerbose() { verbose = true; }

  void setChain(char _ch) { chain = _ch; }
  void setModel(unsigned int _mod) { model = _mod; }
  void setAltAtom(char _a) { altAtom = _a; }

  void setNoHAtoms() { noHAtoms = true; }
  void setAllAtoms() { noHAtoms = false; }
  void setNoSecondary() { noSecondary = true; }
  void setWithSecondary() { noSecondary = false; }
  void setNoConnection() { noConnection = true; }
  void setWithConnection() { noConnection = false; }
  void setNoWater() { noWater = true; }
  void setWithWater() { noWater = false; }
  virtual void loadSpacer(Spacer& sp);
  virtual void loadLigandSet(LigandSet& l);

protected:
  // HELPERS:
  bool setBonds(Spacer& sp);
  bool inSideChain(const AminoAcid& aa, const Atom& at);
  void loadSecondary();
  void assignSecondary(Spacer& sp);

private:
  istream& input;   // input stream
  bool permissive;
  bool valid;
  bool noHAtoms;
  bool noSecondary;
  bool noConnection;
  bool noWater;
  bool verbose;

  char chain;      // chain ID to be loaded
  unsigned int model;      // model number to be loaded
  char altAtom;    // ID of alternate atoms to be loaded

  string helixCode;
  string sheetCode;

  vector<pair<unsigned int, unsigned int> > helixData;
  vector<pair<unsigned int, unsigned int> > sheetData;
};

} // namespace
#endif //_PDB_LOADER_H_

